<?php
class Attendance_Model extends CI_Model{

	public function show($date){
		$query = $this->db
			->query('
				select worker.id,worker.name,attendance.attendance_days as duration,attendance.attendance_salary as price,t.d,t.p
				from attendance
				left join book on book.id = attendance.book_id
				left join worker on worker.id = attendance.worker_id
				left join (select date,worker_id,attendance_days as d,attendance_salary as p from attendance where type = 1)t on t.worker_id = worker.id and t.date = attendance.date
				where attendance.type = 0 and attendance.date = ? and book.incharge_id = ?
				UNION
				select worker.id,worker.name,t.duration,t.price,attendance.attendance_days as d,attendance.attendance_salary as p 
				from attendance
				left join book on book.id = attendance.book_id
				left join worker on worker.id = attendance.worker_id
				left join (select date,worker_id,attendance_days as duration,attendance_salary as price from attendance where type = 0)t on t.worker_id = worker.id and t.date = attendance.date
				where attendance.type = 1 and attendance.date = ? and book.incharge_id = ?',array($date,$_SESSION['id'],$date,$_SESSION['id']))
			->result();
		return array('info'=>$query);
	}

}